﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.AssetManage;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.AssetManage
{
    public class RepairOrderService : IRepairOrderService
    {
        private readonly IRepository<RepairOrder> _RepairOrderService;

        public RepairOrderService(IRepository<RepairOrder> RepairOrderService)
        {
            _RepairOrderService = RepairOrderService;
        }

        public async Task<Response<List<RepairOrder>>> GetRepairOrderPage(RepairOrderSelect select)
        {
            var datas = await _RepairOrderService.GetAllListAsync();
            var result = datas.MapToList<RepairOrder>();
            var totalCount = result.Count();

            result = result.Skip(((select.pageIndex - 1) * select.pageSize)).Take(select.pageSize).ToList();

            return Response<List<RepairOrder>>.Ok(result, totalCount);
        }


        public int GetCount()
        {
            return _RepairOrderService.GetCount();
        }

        public async Task<Response<int>> PutRepairOrder(RepairOrder input)
        {
            var result = await _RepairOrderService.UpdateAsync(input.MapTo<RepairOrder>());
            return Response<int>.Ok(result);
        }







        public class RepairOrderSelect
        {
            public int pageIndex { get; set; }
            public int pageSize { get; set; }
        }
    }
}
